# 四种复合类型示例


# 列表
list1 = [1, 2, 3, 4, 5]
print(list1)

# list添加
list1.append(6)
print(list1)
list1.append("hello")
print(list1)

list1.insert(0, "world")    # 在指定位置0插入元素
print(list1)

# list删除
list1.pop() # 删除末尾元素
print(list1)
list1.pop(1) # 删除指定位置1的元素
print(list1)

list1.remove(2) # 删除指定元素2，不是位置2
print(list1)

list1.append([5, 6])
print(list1)
list1.remove([5, 6])
print(list1)

# list修改
list1[0] = "hello"
print(list1)

# 元组
t = (1, 2, 3, 4, 5)
print(t)

# t[0] = 6    # 'tuple' object does not support item assignment
# print(t)

# 集合
s = {1, 2, 3, 4, 5, 5, 4, 3}
print(s)
s.add(6)
print(s)
s.remove(5)
print(s)
# s[0] = 99 # 'set' object does not support item assignment。可以先删除后再添加
# print(s)

# 字典
d = {"name": "张三", "age": 18, "sex": "男"}
print(d)
d["name"] = "王五"
print(d)
print(d.values())
print(d.keys())
d['school'] = '清华大学'
print(d)
del d['age']
print(d)

list0 = [1, 2]
a, b = list0    # 列表解包
print(a, b)

print(*t) # 元组解包


